package com.infore.airsupervise.biz.impl;

import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.app.MsgConst;
import com.infore.airsupervise.bean.AlarmQueryParamsE;
import com.infore.airsupervise.bean.StationAlarmE;
import com.infore.airsupervise.biz.StationAlarmBiz;
import com.infore.airsupervise.biz.StationAlarmQueryBiz;
import com.infore.airsupervise.http.BaseResponse;
import com.infore.airsupervise.http.HttpAPI;
import com.infore.airsupervise.http.HttpCallBack;
import com.infore.airsupervise.http.HttpUtil;
import com.infore.airsupervise.http.OnServerResponseListener;
import com.infore.airsupervise.utils.JSONUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;

/**
 * @features: 报警搜索业务实现类
 * @author: WuTao
 * @date: 2017/3/17 15:37
 */
public class StationAlarmQueryBizImpl implements StationAlarmQueryBiz{
    @Override
    public Call<BaseResponse> sendAlarmQueryRequest(AlarmQueryParamsE paramsE, final OnServerResponseListener<List<StationAlarmE>> listener) {
        //请求参数
        Map<String,Object> params=new HashMap<>();
        params.put(Constants.USER_ID_KEY,paramsE.getUserId());
        params.put("warningLevel",paramsE.getWarningLevel());
        params.put("warningLevel_1",paramsE.getWarningLevel_1());
        params.put("warningLevel_2",paramsE.getWarningLevel_2());
        params.put("warningLevel_3",paramsE.getWarningLevel_3());
        params.put("warningLevel_4",paramsE.getWarningLevel_4());
        params.put("keyword",paramsE.getKeyWord());
        params.put(Constants.PAGER_NUM_KEY,paramsE.getPageNum());
        params.put("type",paramsE.getType());
        Call<BaseResponse> call= HttpUtil.getHttpService().postParams(HttpAPI.GET_ALRAM_QUERY,params);
        call.enqueue(new HttpCallBack(){
            @Override
            public void onSuccess(int operationCode, BaseResponse response) {
                super.onSuccess(operationCode, response);
                List<StationAlarmE> alarmEList = JSONUtil.parseList(response.getData(),Constants.RESPONSE_BEAN_LIST_KEY,StationAlarmE.class);
                listener.onSucceed(alarmEList,operationCode+"");
            }

            @Override
            public void onException(int errorCode, String title, String desc) {
                super.onException(errorCode, title, desc);
                listener.onFailed(errorCode, MsgConst.GET_DATA_FAILED, desc);
            }

            @Override
            public void onFailed(int operationCode, String desc) {
                super.onFailed(operationCode, desc);
                listener.onFailed(operationCode, MsgConst.GET_DATA_FAILED, desc);
            }


        });
        return call;
    }
}
